package com.ytx.flutter_ytx_plugin
import android.content.Context
import androidx.annotation.NonNull
import com.ytx.flutter_ytx_plugin.x5.X5PlatformViewFactory
import com.ytx.flutter_ytx_plugin.x5.X5Web
import io.flutter.embedding.engine.plugins.FlutterPlugin

/** FlutterYtxPlugin */
class FlutterYtxPlugin : FlutterPlugin {

    lateinit var x5Response: X5Response
    private lateinit var context: Context

    override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
        context = flutterPluginBinding.applicationContext
        x5Response = X5Response(flutterPluginBinding.binaryMessenger)

        X5Web(context,x5Response,flutterPluginBinding.binaryMessenger,)
        flutterPluginBinding.platformViewRegistry.registerViewFactory(
            "my_x5_platform_view", // viewType，与 Flutter 中使用的一致
            X5PlatformViewFactory(flutterPluginBinding.binaryMessenger, x5Response)
        )
    }

    override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
        X5Request.setUp(binding.binaryMessenger, null)

    }
}

